Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
A collection of lightweight utilities for inspecting and manipulating video container formats.
mux.js is a JavaScript library for working with media files, particularly for parsing and generating MPEG-2 Transport Stream (TS) files. It is commonly used in video streaming applications to handle tasks such as demuxing, remuxing, and transmuxing video and audio streams.
Demuxing
Demuxing is the process of separating audio and video streams from a single multiplexed stream. The code sample demonstrates how to use mux.js to demux a Transport Stream (TS) file.
const muxjs = require('mux.js');
const tsSegmentStream = new muxjs.mp2t.TransportStream();
tsSegmentStream.push(data); // data is a Uint8Array of TS packets
tsSegmentStream.flush();
tsSegmentStream.on('data', (segment) => {
console.log('Parsed segment:', segment);
});
Remuxing
Remuxing involves converting one container format to another without changing the underlying codec. The code sample shows how to remux a TS file to an MP4 file using mux.js.
const muxjs = require('mux.js');
const tsSegmentStream = new muxjs.mp2t.TransportStream();
const mp4SegmentStream = new muxjs.mp4.Transmuxer();
tsSegmentStream.pipe(mp4SegmentStream);
tsSegmentStream.push(data); // data is a Uint8Array of TS packets
tsSegmentStream.flush();
mp4SegmentStream.on('data', (segment) => {
console.log('Remuxed segment:', segment);
});
Transmuxing
Transmuxing is the process of converting media data from one format to another, including both the container and the codec. The code sample demonstrates how to transmux a TS file to an MP4 file using mux.js.
const muxjs = require('mux.js');
const transmuxer = new muxjs.mp4.Transmuxer();
transmuxer.push(data); // data is a Uint8Array of TS packets
transmuxer.flush();
transmuxer.on('data', (segment) => {
console.log('Transmuxed segment:', segment);
});
fluent-ffmpeg is a Node.js library that provides a fluent API for working with FFmpeg, a powerful multimedia framework. It supports a wide range of media formats and can be used for tasks such as transcoding, streaming, and muxing. Compared to mux.js, fluent-ffmpeg offers more comprehensive media processing capabilities but requires FFmpeg to be installed on the system.
mp4box is a JavaScript library for parsing and creating MP4 files. It provides a high-level API for manipulating MP4 containers, including adding and removing tracks, extracting metadata, and segmenting files for streaming. While mux.js focuses on MPEG-2 TS files, mp4box is specialized in MP4 files, making it a good alternative for MP4-specific tasks.
hls.js is a JavaScript library that allows you to play HLS (HTTP Live Streaming) streams directly in the browser using Media Source Extensions (MSE). It provides features such as adaptive bitrate streaming, live streaming, and DVR support. While mux.js is more focused on the lower-level processing of media streams, hls.js is designed for playback and streaming of HLS content.
Lightweight utilities for inspecting and manipulating video container formats.
Lead Maintainer: Jon-Carlos Rivera @imbcmdth
Maintenance Status: Stable
Feed in Uint8Array
s of an MPEG-2 transport stream, get out a fragmented MP4:
// create a transmuxer:
var transmuxer = new muxjs.mp4.Transmuxer(initOptions);
// data events signal a new fMP4 segment is ready:
transmuxer.on('data', function (segment) {
// Tada! Now you have an MP4 that you could use with Media Source Extensions
sourceBuffer.appendBuffer(segment.data.buffer);
});
The transmuxer can also parse out supplementary video data like timed ID3 metadata and CEA-608 captions. You can find both attached to the data event object:
transmuxer.on('data', function (segment) {
// create a metadata text track cue for each ID3 frame:
segment.metadata.frames.forEach(function(frame) {
metadataTextTrack.addCue(new VTTCue(time, time, frame.value));
});
// create a VTTCue for all the parsed CEA-608 captions:
segment.captions.forEach(function(cue) {
captionTextTrack.addCue(new VTTCue(cue.startTime, cue.endTime, cue.text));
});
});
Parse MP4s into javascript objects or a text representation for display or debugging:
// drop in a Uint8Array of an MP4:
var parsed = muxjs.mp4.tools.inspect(bytes);
// dig into the boxes:
console.log('The major brand of the first box:', parsed[0].majorBrand);
// print out the structure of the MP4:
document.body.appendChild(document.createTextNode(muxjs.textifyMp4(parsed)));
The MP4 inspector is used extensively as a debugging tool for the transmuxer. You can see it in action by cloning the project and opening the debug page in your browser.
If you're using this project in a node-like environment, just
require() whatever you need. If you'd like to package up a
distribution to include separately, run npm run build
. See the
package.json for other handy scripts if you're thinking about
contributing.
FAQs
A collection of lightweight utilities for inspecting and manipulating video container formats.
The npm package mux.js receives a total of 526,513 weekly downloads. As such, mux.js popularity was classified as popular.
We found that mux.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 21 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.